<div class="layui-fluid" lay-title="网站配置">
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md6">
			<div class="layui-card layui-form" lay-filter="component-form-element">
				<div class="layui-card-header">网站配置</div>
			</div>
			<div class="layui-card">
				<!--<div class="layui-card-header">配置网站信息</div>-->
				<div class="layui-card-body">
					<form class="layui-form" action="" lay-filter="config-web">
						<div class="layui-row layui-col-space10 layui-form-item">
							<div class="layui-col-lg6">
								<label class="layui-form-label">网站名称：</label>
								<div class="layui-input-block">
									<input type="text" name="title" lay-verify="required" placeholder="网站名称" class="layui-input">
								</div>
							</div>
							<div class="layui-col-lg6">
								<label class="layui-form-label">网站域名：</label>
								<div class="layui-input-block">
									<input type="text" name="domain" lay-verify="required" placeholder="网站域名" class="layui-input">
								</div>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">关键词：</label>
							<div class="layui-input-block">
								<input type="text" name="keywords" lay-verify="required" placeholder="关键词" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">描述信息：</label>
							<div class="layui-input-block">
								<textarea name="description" placeholder="描述信息" class="layui-textarea"></textarea>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">版权信息：</label>
							<div class="layui-input-block">
								<textarea name="copyright" placeholder="版权信息" class="layui-textarea"></textarea>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">头部JS：</label>
							<div class="layui-input-block">
								<textarea name="topjs" placeholder="<script src='../jquery.js'></script>" class="layui-textarea"></textarea>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">尾部JS：</label>
							<div class="layui-input-block">
								<textarea name="footerjs" placeholder="<script src='../jquery.js'></script>" class="layui-textarea"></textarea>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">备案信息：</label>
							<div class="layui-input-block">
								<textarea name="beian" placeholder="备案信息" class="layui-textarea"></textarea>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">关站提示：</label>
							<div class="layui-input-block">
								<input type="text" name="tip" placeholder="关站提示" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">关闭访问：</label>
							<div class="layui-input-block">
								<input type="checkbox" name="status" lay-skin="switch" lay-text="是|否">
							</div>
						</div>
						<div class="layui-form-item">
							<div class="layui-input-block">
								<button class="layui-btn" lay-submit lay-filter="config-web">保存配置</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
		<div class="layui-col-md6">
			<div class="layui-card layui-form" lay-filter="component-form-element">
				<div class="layui-card-header">邮箱配置</div>
			</div>
			<div class="layui-card">
				<div class="layui-card-header">配置邮箱信息  (邮箱端口需要填ssl端口)</div>
				<div class="layui-card-body">
					<form class="layui-form" action="" lay-filter="config-email">
						<div class="layui-form-item">
							<label class="layui-form-label">启用邮箱：</label>
							<div class="layui-input-block">
								<input type="checkbox" name="email_status" lay-skin="switch" lay-text="是|否">
							</div>
						</div>
						<div class="layui-row layui-col-space10 layui-form-item">
							<div class="layui-col-lg6">
								<label class="layui-form-label">服务地址：</label>
								<div class="layui-input-block">
									<input type="text" name="smtp_host" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-col-lg6">
								<label class="layui-form-label">服务端口：</label>
								<div class="layui-input-block">
									<input type="text" name="smtp_port" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
								</div>
							</div>
						</div>
						<div class="layui-row layui-col-space10 layui-form-item">
							<div class="layui-col-lg6">
								<label class="layui-form-label">邮箱账号：</label>
								<div class="layui-input-block">
									<input type="text" name="smtp_user" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-col-lg6">
								<label class="layui-form-label">邮箱密码：</label>
								<div class="layui-input-block">
									<input type="pass" name="smtp_pass" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
								</div>
							</div>
						</div>						
						<div class="layui-form-item">
							<label class="layui-form-label">邮箱标题：</label>
							<div class="layui-input-block">
								<input type="text" name="from_head" lay-verify="required" placeholder="{name}, 你有一条新的消息" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">邮箱模板：</label>
							<div class="layui-input-block" id="editor_config">
							</div>
						</div>
						<div class="layui-form-item">
							<div class="layui-input-block">
								<button class="layui-btn" lay-submit lay-filter="config-email">保存配置</button>
							</div>
						</div>

					</form>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	var $ = layui.$;
	let E = window.wangEditor;
	var editor = new E('#editor_config');

	// fcup上传id
	editor.customConfig.fcupId = 'weiyu_id';
	//editor.customConfig.uploadImgShowBase64 = true;
	editor.customConfig.pasteFilterStyle = false;
	editor.customConfig.menus = [
		'head', // 标题
		'bold', // 粗体
		'fontSize', // 字号
		'fontName', // 字体
		'foreColor', // 文字颜色
		'backColor', // 背景颜色
		'link', // 插入链接
		'list', // 列表
		'justify', // 对齐方式
		'quote', // 引用
		'emoticon', // 表情
		'image', // 插入图片
		'undo', // 撤销
		'showCode' // 显示源代码
	];
	editor.create();
</script>
<script>
	layui.use(['admin', 'form'], function(admin, form) {
		var $ = layui.$;
		var element = layui.element;

		// 拉取配置
		admin.get({
			url: layui.api.config + 'typeid',
			async: false,
			success: function(result) {
				let res = result.data;
				$.each(res, function(i, item) {
					if (item.input == 'text') {
						$('input[name="' + item.cfg + '"]').val(item.content);
					}
					if (item.input == 'textarea') {
						$('textarea[name="' + item.cfg + '"]').text(item.content);
					}
					if (item.input == 'rte') {
						editor.txt.html(item.content);
					}
					if (item.input == 'bool') {
						let status = parseInt(item.content);
						if (status == 1) {
							$('input[name="' + item.cfg + '"]').prop("checked", true);
						} else {
							$('input[name="' + item.cfg + '"]').prop("checked", false);
						}
					}
				});
				form.render(null);
			}
		});

		function save(datas) {
			let optime = Math.round(new Date().getTime() / 1000).toString();
			admin.post({
				url: layui.api.config + 'save',
				type: 'post',
				data: datas,
				success: function(result) {
					layer.alert(result.msg, {
						title: '提交提示'
					}, function() {
						// 这里加上时间戳,刷新页面
						admin.navigate('/edit/config/time=' + optime);
					});

				}
			});
		}

		form.on('submit(config-web)', function(data) {
			/** 屏蔽回车 **/
			var theEvent = window.event;
			var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
			if (code == 13) {
				return false;
			}
			let datas = data.field;
			if (!datas.status) {
				datas.status = 2;
			} else {
				datas.status = 1;
			}
			save(datas);
			return false;
		});


		form.on('submit(config-email)', function(data) {
			var theEvent = window.event;
			var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
			if (code == 13) {
				return false;
			}
			let datas = data.field;
			let text = editor.txt.html();
			if (!text) {
				layer.msg('内容不能为空');
				return false;
			}
			datas.from_template = text;
			if (!datas.email_status) {
				datas.email_status = 2;
			} else {
				datas.email_status = 1;
			}
			save(datas);
			return false;
		});

		form.render(null);

	});
</script>
